/* A quick look at the affective polarization Data 
Matt Levendusky 
May 2021 */ 

/* Read in the data*/  
use "MY_PATH_HERE/Affective Polarization Merged Final July 21 2021 Final.dta"

/* Each person is a row, so the unique ID should be the row number */ 
gen uniqueid = _n 

/* To avoid problems in the merge, drop some variables */ 
drop piddemstrg pidrepstrg pidlean pidstem

/* First, rescale the wave 7 (April 2021) data */ 
/* Scales all run low to high, everything on a 0-1 scale to match the first wave */ 

gen fliphypw7 = 6-w7outhypocri
gen flipselfw7 = 6-w7outselfish
gen flipmeanw7 = 6- w7outmean
gen flipmaryw7 = 5- w7outmarry
gen w7outthermsc = w7outtherm/100
gen w7outpatrioticsc = (w7outpatriotic -1)/4
gen w7outintellsc = (w7outintell -1)/4 
gen w7outhonestsc = (w7outhonest -1)/4
gen w7outopenmindsc = (w7outopenmind -1)/4
gen w7outgenroussc = (w7outgenrous -1)/4
gen fliphypw7sc = (fliphypw7  -1)/4
gen flipselfw7sc = (flipselfw7 -1)/4
gen flipmeanw7sc = (flipmeanw7 -1)/4
gen w7outtrustsc = (w7outtrust -1)/4
gen w7outfriendssc = (w7outfriends -1)/3
gen w7outneighborsc = (w7outneighbor  -1)/3
gen  flipmaryw7sc = (flipmaryw7 -1)/3

/* Scale the AP Measures: Full Set ONLY in Waves 1 & 4 */ 
rename allout allout_w1 
egen allout_w4 = rowmean(w7outthermsc  w7outpatrioticsc w7outintellsc w7outhonestsc w7outopenmindsc w7outgenroussc fliphypw7sc flipselfw7sc flipmeanw7sc w7outtrustsc w7outfriendssc w7outneighborsc flipmaryw7sc)

/* Call this AP, higher values mean your more negative toward the other side */ 
gen affpol_w1 = 1 - allout_w1
gen affpol_w4 = 1 - allout_w4

/* Just make a version that's stable across waves (this is the original AP measure) */ 
gen apstable_w1 = affpol_w1 
gen apstable_w2 = affpol_w1 
gen apstable_w3 = affpol_w1 
gen apstable_w4 = affpol_w1 

/* In this data, we're going to turn the data into panel data */ 
/* To do that, we rename using the following conventions */ 
/* w1: summer 2019 wave */ 
/* w2: April 2020 wave */ 
/* w3: October 2020 wave */ 
/* w4: April 2021 wave */ 

/* Affective polarization measures */ 

/* Put 2020 wave FT measures on 0-1 scale */
gen w4out = wave4outtherm/100 
gen w4in = wave4intherm/100 
gen w5out = wave5outtherm/100 
gen w5in = wave5intherm/100 
gen w7inthermsc = w7intherm/100 

rename feelingtherm_outgroup ftout_w1 
rename feelingtherm_ingroup ftin_w1 
rename w4out ftout_w2 
rename w4in ftin_w2 
rename w5out ftout_w3  
rename w5in ftin_w3 
rename w7outthermsc ftout_w4 
rename w7inthermsc ftin_w4 

/* Partisanship */ 
gen partychange = 0
recode partychange  0/0 = 1 if (wave2pid < 4 & w7pid > 4) | (wave2pid > 4 & w7pid < 4)
tab partychange if inwave7 == 1
rename wave2pid partyid_w1 
rename wave5pid partyid_w3 
rename w7pid partyid_w4 

/* Severity of COVID-19 */ 
/* Look at the maximum severity across personal, household, and friends */ 
gen covidmax_w3 = max(wave5persevere, wave5housevere, wave5frisevere)
gen covidmax_w4 = max(w7housevere, w7frisevere, w7persevere) 
gen delta_covidmax = covidmax_w4 - covidmax_w3 

/* Evaluations of Political Leaders */ 
rename cvatrump trumpapr_w2 
rename cvabiden bidenapr_w2 
rename cvafaucit fauciapr_w2 
rename cvacdc cdcapr_w2 
rename wave5trump trumpapr_w3 
/* rename wave5biden bidenapr_w3  --> Biden not asked that wave??? */ 
rename wave5fauci fauciapr_w3 
rename wave5cdc cdcapr_w3  
rename wave5fda fdaapr_w3 
rename wave5mayor mayorapr_w3
rename w7trump trumpapr_w4
rename w7biden bidenapr_w4 
rename w7fauci fauciapr_w4 
rename w7cdc cdcapr_w4 
rename w7fda fdaapr_w4 
rename w7mayor mayorapr_w4 

/* Perceived Safety of Various Actions */ 
/* For comparability, just look at the common items */ 

egen safety_w3 = rowmean(safegym saferesaturant safesocializeindoor safeplane safehaircut savemovie safesportsinside safeconcertinside)
gen unsafe_w3 = 5-safety_w3

alpha w7safegym w7saferestau w7safesocial w7safeplane w7safehaircut w7safemovie w7safesports w7safeconcerts 
egen safety_w4 = rowmean(w7safegym w7saferestau w7safesocial w7safeplane w7safehaircut w7safemovie w7safesports w7safeconcerts)
gen unsafe_w4 = 5-safety_w4 

/* Individual Safety Activities */ 

rename safegym safegym_w3 
rename saferesaturant saferestaurant_w3 
rename safesocializeindoor safesocial_w3 
rename safeplane safeplane_w3 
rename safehaircut safehaircut_w3 
rename savemovie safemovie_w3 
rename safesportsinside safesport_w3 
rename safeconcertinside safeconcert_w3 
rename w7safegym safegym_w4
rename w7saferestau saferestaurant_w4 
rename w7safesocial safesocial_w4 
rename w7safeplane safeplane_w4
rename w7safehaircut safehaircut_w4 
rename w7safemovie safemovie_w4
rename w7safesports safesport_w4
rename w7safeconcert safeconcert_w4 


/* Did You Engage in Various Behaviors? */  

gen behavior_w2 = (wash + workhome + handsan + canceltrave + avoid10 + feet + facemask + gloves + nostore + delivery + cooked + lessoutside + allhome + extfood)

gen behavior_w3 = (wave5washhands + wave5workhome + wave5handsanit + wave5canceltravel + wave5avoidgather + wave56feet + wave5facemask + wave5gloves + wave5nogrocery+ wave5ordergrocery + wave5cookhome+ wave5notoutside+ wave5stayhome +wave5extrafood)

gen behavior_w4 =  (w7washhands + w7workhome + w7handsanit + w7canceltravel + w7avoidgather + w76feet + w7facemask + w7twofacemask + w7gloves + w7nogrocery + w7ordergrocery + w7cookhome + w7notoutside + w7stayhome + w7extrafood)

rename none none_w2 
rename wave5none none_w3 
/* rename w7none none_w4 NOT ASKED?? */ 

/* Look at various activities individually */ 
rename wash washhands_w2 
rename workhome workhome_w2 
rename handsan handsan_w2 
rename canceltrave canceltravel_w2 
rename avoid10 nogather_w2
rename feet sixfeet_w2 
rename facemask facemask_w2 
rename gloves gloves_w2 
rename nostore nostore_w2 
rename delivery delivery_w2 
rename cooked cooked_w2 
rename lessoutside lessoutside_w2 
rename allhome allhome_w2 
rename extfood extfood_w2 
rename wave5washhands washhands_w3
rename wave5workhome workhome_w3 
rename wave5handsanit handsan_w3 
rename wave5canceltravel canceltravel_w3 
rename wave5avoidgather nogather_w3
rename wave56feet sixfeet_w3 
rename wave5facemask facemask_w3 
rename wave5gloves gloves_w3 
rename wave5nogrocery nostore_w3 
rename wave5ordergrocery delivery_w3 
rename wave5cookhome cooked_w3 
rename wave5notoutside lessoutside_w3 
rename wave5stayhome allhome_w3 
rename wave5extrafood extfood_w3 
rename w7washhands washhands_w4 
rename w7workhome workhome_w4 
rename w7handsanit handsan_w4 
rename w7canceltravel canceltravel_w4 
rename w7avoidgather nogather_w4
rename w76feet sixfeet_w4 
rename w7facemask facemask_w4 
rename w7twofacemask doublemask_w4
rename w7gloves gloves_w4 
rename w7nogrocery nostore_w4 
rename w7ordergrocery delivery_w4 
rename w7cookhome cooked_w4 
rename w7notoutside lessoutside_w4 
rename w7stayhome allhome_w4 
rename w7extrafood extfood_w4  

/* Support for Various Policies */ 
gen flipfinenomask = 5- finenomask
egen wave5policya = rowmean(requireelementry requirehighschool businesscapacity flipfinenomask)
gen policy_w3 = 5-wave5policya

gen nvflipfinenomaskw7 = 5- w7finenomask
egen w7nvpolicya = rowmean(w7requireelementry w7requirehighschool w7businesscapacity nvflipfinenomaskw7)
gen policy_w4 = 5-w7nvpolicya


gen vflipfinenomaskw7 = 5- w7vacfinenomask
egen w7VACpolicya = rowmean( w7vacrequireelementry w7rvacequirehighschool w7vacbusinesscapacit vflipfinenomaskw7)
gen VACpolicy_w4 = 5-w7VACpolicya 

/* Democratic Norms Items */ 
gen fmethods_w1 = 5- methods
gen fmethods_w4 = 5-w7methods
gen fexecpower_w1 = 5- exec_power
gen fexecpower_w4 = 5- w7exec_power
gen finherentunequal_w1 = 5 - inherent_unequal
gen finherentunequal_w4 = 5-w7inherent_unequal
gen fprotest_w1 = 5-protest
gen fprotest_w4 = 5-w7protest 
rename checks checks_w1 
rename w7checks checks_w4
rename institu_respect institution_w1 
rename w7institu_respect institution_w4
rename vote vote_w1 
rename w7vote vote_w4
rename political_voice voice_w1 
rename w7political_voice voice_w4

/* Take this wide data and make it long */ 
reshape long allout affpol apstable ftout ftin pid covidmax trumpapr bidenapr fauciapr cdcapr fdaapr mayorapr safety unsafe safegym saferestaurant safesocial safeplane safehaircut safemovie safesport safeconcert behavior washhands workhome handsan canceltravel nogather sixfeet facemask gloves nostore delivery cooked lessoutside allhome extfood  none policy VACpolicy fmethods fexecpower finherentunequal fprotest checks institution vote voice, i(uniqueid) j(yrs, string)  
gen year = 1 if yrs == "_w1" 
replace year = 2 if yrs == "_w2" 
replace year = 3 if yrs == "_w3" 
replace year = 4 if yrs == "_w4" 
xtset uniqueid year 
 
/* FT changes over time? */ 
gen ft_diff = ftin - ftout 
xtreg ftout i.year, fe robust 
xtreg ftin i.year, fe robust 
xtreg ft_diff i.year, fe robust 
/* super-modest differences, basically just tiny effects of 2-3 degrees */ 
 
/* Run a panel regression for a few items */ 

xtreg fauciapr c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg fauciapr c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust  
xtreg cdcapr c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg cdcapr c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust  
xtreg fdaapr c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg fdaapr c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust  
/* we get a bigger effect of partisan animus over time for these three scientific figures */ 
/* suggests that as they become polarized, animus bites more */  

/* Moderation by severity? */ 
xtreg fauciapr c.apstable##c.year##c.covidmax if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg fauciapr c.apstable##c.year##c.covidmax if rep == 1 & partyid != 4 & partychange == 0, fe robust  
/* goes to mush */ 

/* Safety of various items? */ 
xtreg unsafe c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg unsafe c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
/* general time trend but no weaking of AP effects, just basically everything things things are safer over time */ 

/* Behaviors Mapping Into AP? */ 
xtreg behavior c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg behavior c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg none c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
/* Dems generally do fewer behaviors over time, but for Rs, there's an AP*time interaction: AP effects getting larger! */ 
/* It's the highest animosity Reps who are reducing behaviors over time the most (low AP reps have little change) */ 
/* It's the high AP reps who say they are doing "none" of the activities more over time */ 

/* Is the moderating effect of severity weakening over time? */ 
xtreg behavior c.apstable##c.year##c.covidmax if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg behavior c.apstable##c.year##c.covidmax if rep == 1 & partyid != 4 & partychange == 0, fe robust 
/* Just a mess, but maybe for Rs more severe experience w/ COVID makes you more cautious? */ 

/* Support for policies? */ 
xtreg policy c.apstable##c.year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg policy c.apstable##c.year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
/* Everyone is less supportive of these policies over time, but high animus Demorats have a less steep slope */  

/* Democratic norms */ 

**fmethods fexecpower finherentunequal fprotest checks institution vote voice

xtreg fmethods c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust  
xtreg fmethods c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg fexecpower c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg fexecpower c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg institution c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg institution c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg checks c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg checks c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg finherentunequal c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg finherentunequal c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg vote c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg vote c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
xtreg voice c.apstable##year if rep == 1 & partyid != 4 & partychange == 0, fe robust 
xtreg voice c.apstable##year if rep == 0 & partyid != 4 & partychange == 0, fe robust 
/* differences on: exec power, institutions, checks, voice (same direction for both) */ 
/* some year trends too (matched John's email) */  

/* Dump the data to R to make some quick graphs */ 
save "MY_PATH_HERE/for_r_for_graphs_y.dta", replace 

